package com.ruibang.glass.sale.controller;


import com.ruibang.glass.sale.domain.req.GSaleReturnIventoryReq;
import com.ruibang.glass.sale.domain.req.SaleshippingApplicationReq;
import com.ruibang.glass.sale.entity.GSaleOrderManagement;
import com.ruibang.glass.sale.entity.SaleShippingApplication;
import com.ruibang.glass.sale.entity.SalesShippingItems;
import com.ruibang.glass.sale.service.GSaleReturnExchangeOrderService;
import com.ruibang.glass.sale.service.GSaleReturnInventoryService;
import com.ruibang.glass.sale.service.SaleShippingApplicationService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author mameng
 */
@Api(tags = "发货申请")
@RestController
@RequestMapping("/api/glass/sale/shipping/application")
public class GSaleShippingApplicationController {
    @Autowired
    private SaleShippingApplicationService saleShippingApplicationService;

    @PostMapping("list")
    @ApiOperation(value = "发货申请列表", response = ResultBody.class)
    public ResultBody list(@RequestBody SaleshippingApplicationReq saleshippingApplicationReq) {
        return ResultBody.success(saleShippingApplicationService.getPage(saleshippingApplicationReq));
    }

    @PostMapping("moreList")
    @ApiOperation(value = "多发货订单统计", response = ResultBody.class)
    public ResultBody moreList(@RequestBody SaleshippingApplicationReq saleshippingApplicationReq) {
        return ResultBody.success(saleShippingApplicationService.moreList(saleshippingApplicationReq));
    }

    @GetMapping("getMoreList")
    @ApiOperation(value = "多发货下拉选择", response = ResultBody.class)
    public ResultBody getMoreList() {
        return ResultBody.success(saleShippingApplicationService.getMoreSelectList());
    }

    @PostMapping("add")
    @ApiOperation(value = "发货申请添加", response = ResultBody.class)
    public ResultBody addSaleShippingApplication(@RequestBody List<SaleShippingApplication> saleShippingApplicationList) {
        saleShippingApplicationService.addSaleShippingApplication(saleShippingApplicationList);
        return ResultBody.success();
    }

    @PostMapping("addLessShipping")
    @ApiOperation(value = "发货申请再次发货", response = ResultBody.class)
    public ResultBody addLessShipping(@RequestBody SaleShippingApplication saleShippingApplication) {
        saleShippingApplicationService.addLessShipping(saleShippingApplication);
        return ResultBody.success();
    }

    @PostMapping("updateSaleShippingApplication")
    @ApiOperation(value = "发货申请更新", response = ResultBody.class)
    public ResultBody updateSaleShippingApplication(@RequestBody SaleShippingApplication saleShippingApplication) {
        saleShippingApplicationService.updateSaleShippingApplication(saleShippingApplication);
        return ResultBody.success();
    }

    @GetMapping("getOne/{id}")
    @ApiOperation(value = "详情", response = ResultBody.class)
    public ResultBody getOneSaleShippingApplication(@PathVariable("id") String id) {
        return ResultBody.success(saleShippingApplicationService.getOneSaleShippingApplication(id));
    }

    @GetMapping("getById/{id}")
    @ApiOperation(value = "查看详情", response = ResultBody.class)
    public ResultBody getById(@PathVariable("id") String id) {
        return ResultBody.success(saleShippingApplicationService.getOneSaleShippingApplication(id));
    }

    @GetMapping("getProductList/{id}")
    @ApiOperation(value = "更具发货Id获取下拉商品", response = ResultBody.class)
    public ResultBody getProductList(@PathVariable("id") String id) {
        return ResultBody.success(saleShippingApplicationService.getProductList(id));
    }

    @GetMapping("getMaterialOUTNumber")
    @ApiOperation(value = "测试", response = ResultBody.class)
    public String getMaterialOUTNumber() {
      return  saleShippingApplicationService.getMaterialOUTNumber();
    }


    @GetMapping("updateQs/{id}")
    @ApiOperation(value = "发货签收", response = ResultBody.class)
    public ResultBody updateQs(@PathVariable("id") String id) {
        saleShippingApplicationService.updateQs(id);
        return ResultBody.success();
    }


    //更具订单获取产品下拉
    @GetMapping("getProductByOrderNumber/{orderNumber}")
    @ApiOperation(value = "更具订单订单号获取产品", response = ResultBody.class)
    public ResultBody getProductByOrderNumber(@PathVariable("orderNumber") String orderNumber) {
        return ResultBody.success(saleShippingApplicationService.getProductByOrderNumber(orderNumber));
    }

    //更具订单获取产品下拉
    @PostMapping("getATypeList")
    @ApiOperation(value = "获取托盘号", response = ResultBody.class)
    public ResultBody getATypeList(@RequestBody SalesShippingItems salesShippingItems) {
        return ResultBody.success(saleShippingApplicationService.getATypeList(salesShippingItems));
    }

    @PostMapping("updateSaleShippingApplicationById")
    @ApiOperation(value = "修改发货数量", response = ResultBody.class)
    public ResultBody SaleShippingApplicationById(@RequestBody SaleShippingApplication saleShippingApplication) {
        saleShippingApplicationService.saleShippingApplicationById(saleShippingApplication);
        return ResultBody.success();
    }


    //更具订单号获取发货单号下拉
    @GetMapping("getShippingNumber/{orderNumber}")
    @ApiOperation(value = "获取下拉发货单号", response = ResultBody.class)
    public ResultBody getShippingNumber(@PathVariable("orderNumber") String orderNumber) {
        return ResultBody.success(saleShippingApplicationService.getShippingNumber(orderNumber));
    }


    @GetMapping("updateSaleQualityById/{id}")
    @ApiOperation(value = "修改发货数量", response = ResultBody.class)
    public ResultBody updateSaleQualityById(@PathVariable("id") String id) {
        saleShippingApplicationService.updateSaleQualityById(id);
        return ResultBody.success();
    }

}
